﻿@using PagedList
@using PagedList.Mvc
@model PagedList.IPagedList<KVP.KVPNew<long, string>>
@{
    ViewBag.Title = "List";
    int i = Model.FirstItemOnPage;
    int j = 0;
}
<h2>@PMKB_DAL.PMKBEntities_resource.Tag_Found_Generic(Model.TotalItemCount)
</h2>
<script type="text/javascript">
    var viewmodel = {tagarray:[] };
   var  myObservableArray = ko.observableArray();
   function changetext(object) {
       if ($.trim($(object).val()) != $.trim($.data(object, "key"))) {
           $(object).next().val(true);
           $('#btnSave').attr('disabled', 'enabled');
           alert('enabled)');
       }
       else {
           $('#btnSave').attr('disabled', 'disabled');
           alert('disabled');
       }
       
   }
   $(function () {
       var elements = $("table tr td input:text");
       for (var i = 0; i < elements.size(); i++) {
           $.data(elements[i], "key", $(elements[i]).val());
       }
       $("table tr td input:text").bind("keyup", function (evt) {
           if ($.trim($(this).val()) != '' && $.trim($(this).val()) != $.trim($.data(this, "key"))) {
               $(this).next().val(true);
               $('#btnSave').removeAttr('disabled'); 

           }
           else {
               $('#btnSave').attr('disabled','disabled'); 
               $(this).next().val(false);

           }
          
       });
   }


    );
   
</script>
@using (@Html.BeginForm("SaveData", "Tag"))
{
    <table>
        <tr>
            <th>
                Nr
            </th>
            <th>@PMKB_DAL.PMKBEntities_resource.Tag_TagName_Label
            </th>
            <th>
                Links count
            </th>
            <th>
                Actions
            </th>
        </tr>
        <tbody >
        @foreach (var item in Model)
        {
            string NameTag = string.Format("divTag_{0}", @item.Key);
            <tr>
                <td>
                    @i
                </td>
                <td>
                    @*<div id="@NameTag">
            @item.Value</div>*@
                    @if (@j < Model.Count)
                    {
                        @Html.HiddenFor(x => x[j].Key);
                        @Html.TextBoxFor(x => x[j].Value);
                                                       
                        @Html.HiddenFor(x => x[j].Modified);
                                                           j++;
                    }
                </td>
                <td>@item.AdditionalDataLong
                </td>
                <td>
                    @*<a href="javascript:renameTag('@Url.Action(MVC.Tag.RenameTag())',@item.Key,'@item.Value', function(name) { $('#'+ '@NameTag').html(name); })">
                        Rename</a>*@
                    @Html.ActionLink(PMKB_DAL.PMKBEntities_resource.Link_Tag_View_Param(""), MVC.Tag.Index(item.Key.ToString(), 1, 10))
                    @PMKB_DAL.PMKBEntities_resource.Tag_Export
                </td>
            </tr>
    
        
                    i++;
                 
        }
           </tbody>
    </table>
        if (Model.PageCount > 1)
        { 
    @Html.PagedListPager(Model, page => Url.Action(MVC.Tag.List(page, Model.PageSize)), PagedListRenderOptions.PageNumbersOnly)
        }
    <input type="submit" value="Save" id="btnSave" disabled=disabled />
}